package com.bkq.viettravel;



import com.bkq.viettravel.LoaderImageView;




import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class FavoritesArrayAdapter extends ArrayAdapter<String> {
	
	 private final Activity context;
	 private final String[] tv_travel_name;
	 private final String[] tv_travel_intro;
	 private final String[] img_travel;
	 
	 public FavoritesArrayAdapter(Activity context, String[] name,String[] intro,String[] image) {
	 super(context, R.layout.favorites_row, name);
	 this.context = context;
	 this.tv_travel_name = name;
	 this.tv_travel_intro=intro;
	 this.img_travel=image;
	 }
	 
	 // static to save the reference to the outer class and to avoid access to
	 // any members of the containing class
	 static class ViewHolder {
	 public LoaderImageView image_travel;
	 public TextView txt_name_travel;
	 public TextView txt_intro_travel;
	 
	 }
	 
	 @Override
	 public View getView(int position, View convertView, ViewGroup parent) {
	 // ViewHolder will buffer the assess to the individual fields of the row
	 // layout
	 
	 ViewHolder holder;
	 // Recycle existing view if passed as parameter
	 // This will save memory and time on Android
	 // This only works if the base layout for all classes are the same
	 View rowView = convertView;
	 if (rowView == null) {
	 LayoutInflater inflater = context.getLayoutInflater();
	 rowView = inflater.inflate(R.layout.favorites_row, null, true);
	 holder = new ViewHolder();
	 
	 holder.txt_name_travel = (TextView) rowView.findViewById(R.id.favorites_row_name);
	 holder.txt_intro_travel = (TextView) rowView.findViewById(R.id.favorites_row_intro);
	 holder.image_travel = (LoaderImageView) rowView.findViewById(R.id.favorites_row_img);
	 rowView.setTag(holder);
	 } 
	 else {
	 holder = (ViewHolder) rowView.getTag();
	 }
	 
	 holder.txt_name_travel.setText(tv_travel_name[position]);
	 holder.txt_intro_travel.setText(tv_travel_intro[position]);
	 holder.image_travel.setImageDrawable((img_travel[position]));
	
	 return rowView;
	 }
	 

	 
	}